iT邦幫忙

2022 iThome 鐵人賽

DAY 18
0
  • Codetags和TODO注釋:
    Codetags(程式碼標籤)的形式為帶有大寫標籤的注釋。像是TODO並寫上簡短描述可以幫助提示未來須繼續完成工作。另外像是FIXME提醒這部分的程式未能有效運作。
  • 行內注釋:
    行內注釋為放在程式碼的尾端,此行內注釋多數簡短若需要更長的空間可以改用單獨注釋行來描述。此種行內注釋方法多數用在變數。
month = 2 # 月份
  • 區塊注釋: 若注釋跨多行則可以連續使用多個單行注釋。可以使空行注釋把中的段落分開。
#Here is a comment about this code
#Several single-line comments in a row.
#These are known as block comments.
If sex==’man’:
	print(“he is a man”)
elif sex==’woman:
	print(“she is a woman”)
  • 多行注釋: 若注釋跨越多行也可以使用一個多行注釋還處理。
'''This is a
Multiline comment.
'''
if sex=="man":
	print("he is a man")
elif sex=="woman":
	print("she is a woman")
  • 總結型注釋:
    通常用來解說一段程式內容,總結型注釋會在這些段落的開頭佔據一行。與單行注釋不同之處其描述程式碼更高層次整體概念。
# This is a sample code
If sex=="man":
	print("he is a man")
elif sex=="woman":
	print("she is a woman")

上一篇
Day17: Python 匿名函式
下一篇
Day19:Python的物件導向
系列文
人生苦短我用python寫出乾淨程式碼22
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言